<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #box {
      width: 100px;
      height: 100px;
      background: red;
    }
  </style>
</head>
<body>

  <div id="root"></div>

  <script>

    function createVdom({tagName, attrs = {}, children=[]}) {
      const rDom = document.createElement(tagName);
      Object.keys(attrs).forEach(key => {
        rDom.setAttribute(key, attrs[key]);
      })
      children && children.length > 0 && children.forEach(item => {
         if (typeof item === 'string') {
          rDom.appendChild(document.createTextNode(item))
         } else if (typeof item === 'object'){
           console.log('item:', item)
          rDom.appendChild(createVdom(item))
         }
      })
      return rDom;
    }

    let ele = createVdom(
      {
        tagName: 'div',
        attrs: { class: 'box' },
        children:[
          {
            tagName: 'span', attrs: { class: 'span' }
          }
        ]
      }
     )
     console.log('ele:', ele)

    const root = document.getElementById('root')
    console.log(root.innerHTML)
    root.appendChild(ele)

  </script>
</body>
</html>
